package com.jingwu.example.service;

import com.jingwu.example.repository.BarRepository;
import com.jingwu.example.repository.FooRepository;
import com.jingwu.example.exception.DummyException;
import com.jingwu.example.pojo.entity.BarDO;
import com.jingwu.example.pojo.entity.FooDO;
import com.jingwu.example.pojo.vo.FooVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * @author 菁芜
 * @date 2021/1/3 -16:12
 */
@Service
public class FooService {

    @Autowired
    private FooRepository fooRepository;

    @Autowired
    private BarRepository barRepository;

    public FooVO get(String id) {
        BarDO barDO = barRepository.getByFooId(id);
        FooDO fooDO = fooRepository.get(id);
        FooVO foo = new FooVO();
        foo.setStatus(barDO.getType());
        foo.setId(id);
        foo.setName(fooDO.getName() + "-suffix");
        switch (barDO.getType()) {
            case FAILED:
                foo.setContent("this is failed result");
                break;
            case SUCCESS:
                foo.setContent("this is success result");
                break;
            default:
                throw new DummyException("some exception happened!");
        }
        return foo;
    }

}
